// pages/returnaddress/returnaddress.js
import baseteam from '~/utils/teamleader.js'
import basesup from '~/utils/supplier.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        addressjson: [],
        radio: 0,
    },
    naveback() {
        setTimeout(() => {
            wx.navigateBack()
        }, 300);
    },
    async getaddress() {
        let resdata = await basesup.returnaddresslist()
        console.log(resdata)
        if (resdata.code == 200) {
            this.setData({
                addressjson: resdata.data.Result.records
            })
            for (let i = 0; i < resdata.data.Result.records.length; i++) {
                if (resdata.data.Result.records[i].isDefault == 1) {
                    this.setData({
                        radio: resdata.data.Result.records[i].id
                    })
                }
            }
        } else {
            setTimeout(() => {
                this.naveback()
            }, 2000);
        }

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.setData({
        //     radio:"0"
        // })
        this.getaddress()


    },
    navenext(data) {
        // console.log(data)
        wx.navigateTo({
            url: `../returnaddressedit/returnaddressedit?ressid=${data.currentTarget.dataset.ressid}`,
        })
    },
    addmodify() {
        wx.navigateTo({
            url: '../returnaddressedit/returnaddressedit',
        })
    },
    radioonChange(item) {
        console.log(item)
        this.setData({
            radio: item.detail
        })
        // let pages = getCurrentPages();
        // let prevPage = pages[pages.length - 2];
        // for (const values in this.data.addressjson) {
        //     if (this.data.addressjson[values].id == item.detail) {
        //         prevPage.setData({
        //             "mailingAddress": this.data.addressjson[values].detailedAddress,
        //             "recipients": this.data.addressjson[values].recipients,
        //             "contactNumber": this.data.addressjson[values].phone,
        //             "province": this.data.addressjson[values].province,
        //         })
        //         setTimeout(() => {
        //             this.naveback()
        //         }, 600);
        //         return false
        //     }
        // }

    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getaddress()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})